<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商家管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/bus-style.css" media="all">
    <style>
        .nums{
            font-size: 20px;
        }
    </style>
</head>
<body>

<div class="layui-container">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <div class="layui-col-sm12" style="padding-left: 25px">
                <blockquote class="layui-elem-quote layui-quote-nm">
                    1. <span class="red">商品编码：${proCode}</span><br>
                    2. 红包余额：&nbsp;&nbsp;&nbsp;&nbsp;<span class="nums">${redPacket.totalMoney}</span>元<br>
                    3. 单个红包金额：&nbsp;&nbsp;&nbsp;&nbsp;<span class="nums">${redPacket.perMoney}</span>元<br>
                </blockquote>
            </div>
            <hr>
            <form class="layui-form" id="activityEditForm">
                <input type="hidden" name="id" value="${redPacket.id}">
                <input type="hidden" id="proCode" name="proCode" value="${proCode}">
                <%--<input type="hidden" name="status" value="${redPacket.status}">--%>
                <c:if test="${redPacket.id == null}">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>红包类型</label>
                        <div class="layui-input-block">
                            <select name="payType">
                                <option value="">请选择</option>
                                <c:forEach items="${typeList}" var="t">
                                    <option value="${t.id}">${t.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </c:if>
                <c:if test="${redPacket.id != null}">
                    <input type="hidden" name="payType" value="${redPacket.payType}">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*&nbsp;</span>红包类型</label>
                        <div class="layui-input-block">
                            <select name="payType" disabled>
                                <option value="">请选择</option>
                                <c:forEach items="${typeList}" var="t">
                                    <option value="${t.id}" ${redPacket.payType==t.id?'selected':''}>${t.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </c:if>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>红包总金额</label>
                    <div class="layui-input-block">
                        <input type="text" name="totalMoney" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>单个金额</label>
                    <div class="layui-input-block">
                        <c:if test="${redPacket.id == null}">
                            <input type="text" name="perMoney" autocomplete="off" class="layui-input">
                        </c:if>
                        <c:if test="${redPacket.id != null}">
                            <input type="text" name="perMoney" autocomplete="off"
                                   value="${redPacket.perMoney}" class="layui-input" readonly>
                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 5px;">
                                商品未完全领取完毕，无法更改单个金额。
                            </blockquote>
                        </c:if>
                    </div>
                </div>
            </form>
            <div class="layui-form-item layui-layout-admin">
                <div class="layui-input-block">
                    <div class="layui-footer" style="left: 0;">
                        <button class="layui-btn" onclick="FormSubmit('#activityEditForm','/product/editRedPacket')">保存</button>
                        <c:if test="${canClose}">
                            <button class="layui-btn layui-btn-warm" onclick="shelfRedPacket()">下架活动</button>
                        </c:if>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form'], function(){
        var $ = layui.$;
    });

    function shelfRedPacket(){
        var proCode = $("#proCode").val();
        if (proCode.length < 1){
            layer.msg("获取商品信息失败",{icon:2});
            return;
        }
        layer.confirm('确定操作吗？', function(){
            $.ajax({
                url: '/product/handleRedStatus',
                data: {"proCode": proCode},
                dataType: "json",
                type: "post",
                success: function (data) {
                    if (data.status) {
                        layer.msg(data.desc,{icon:1});
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000)
                    } else {
                        layer.msg(data.desc,{icon:2});
                    }
                }
            });
        });
    }
</script>
</body>
</html>